let is_letter = function
	| 'a'..'z' | 'A'..'Z'	-> true
	| _			-> false



let next_word s i buff =
	let j = ref (0) in
		j := i;
		while not (is_letter (String.get s !j)) && !j < (String.length s -1) do
			j := !j + 1
		done;
		while is_letter (String.get s !j) && !j < (String.length s -1) do
				Buffer.add_char buff (String.get s !j);
				j := !j + 1
		done;
	!j

let word_iter f chaine =
	let i = ref (0) and buff = Buffer.create 25 in
		while !i < (String.length chaine -1) do
			i := next_word chaine !i buff;
			if Buffer.length buff <> 0 then
				f (Buffer.contents buff);
			Buffer.clear buff
		done

let print_word x = Printf.printf "|%s|\n" x

module IString =
        struct
                type t = string
                let compare s1 s2 =
                        String.compare
                                (String.uppercase s1)
                                (String.uppercase s2)
        end

module StringSet = Set.Make (IString)

let check ss s =
	Printf.printf "%S : " s;
	if IString.compare s ss = 0 then
		Printf.printf "Ok"
	else
		Printf.printf "Erreur";
	Printf.printf "\n"

let ldico = [
  "une";
  "phrase";
  "pour";
  "tester";
  "notre";
  "code";
  "avec";
  "un";
  "peu";
  "de";
  "ponctuation";
]

let dico =
  List.fold_left (fun d w -> StringSet.add w d) StringSet.empty ldico

let main () =
  let s = "Une phrase pour tester notre code, avec un peu de ponctuation.\n" in
    begin
      Printf.printf "s = %S\n" s;
      word_iter (check dico) s;
      Printf.printf "\n%!";
      exit 0
    end


 
let _ = main ()

